package gameEngine.com.state;

import android.graphics.Color;
import gameEngine.com.*;

public class StateSelectLevel extends MainActivity {

	public static int[] menuMap = { R.string.STRING_MAP1, R.string.STRING_MAP2,
			R.string.STRING_MAP3, R.string.STRING_MAP4, R.string.STRING_MAP5 };
	public static int[][] menuLevel = { { 1, 2, 3, 4, 5 },
			{ 6, 7, 8, 9, 10 } };
	public static int menuMapUnLock = 1; // map current
	public static int menuLevelUnLock = 3;// level current

	public static int menuMapTopX = 130;
	public static int menuMapTopY = 160;
	public static int menuSelectLevelTopX = 450;
	public static int menuSelectLevelTopY = 160;
	public static int menuElementWidth = 170;
	public static int menuElementHeight = 50;
	public static int MENU_COL_SPACE = 200;
	public static int menuElementSpace = 10;
	public static int menuTouchOffsetX = -90;
	public static int menuTouchOffsetY = -27;
	public static int menuTextOffsetX = 0;
	public static int menuTextOffsetY = 0;
	public static int menuselectMapIndex = 0;

	// String mess = getResources().getString(R.string.mess_1)
	public static void SendMessageStateSelectLevel(int type) {
		switch (type) {
		case MESSAGE_CTOR:
			if (spriteMenuButton == null)
				spriteMenuButton = new Sprite("sprite/ui/menubutton.spr", true);
			if (spriteMenu == null)
				spriteMenu = new Sprite("sprite/ui/menu.sprt");
			StateConfirm.setConfirmDeActive();
			break;
		case MESSAGE_UPDATE:
			if (StateConfirm.isConfirm) {
				StateConfirm.SendMessageStateConfirm(MESSAGE_UPDATE);
				return;
			}
			StateMainMenu.UpdateMainmenu();
			for (int i = 0; i < menuLevel.length; i++)
				for (int j = 0; j < menuLevel[0].length; j++) {
					if (i * menuLevel[0].length + j < menuLevelUnLock)
						if (isTouchReleaseInRect(menuSelectLevelTopX + i * MENU_COL_SPACE + menuTouchOffsetX, menuSelectLevelTopY
								+ menuTouchOffsetY + j
								* (menuElementHeight + menuElementSpace),
								menuElementWidth, menuElementHeight)) {

							StateGameplay.level = i * menuLevel.length + j + 1;
							StateLoading.loadingtype = StateLoading.LOADING_TYPE_GAME_TO_GAME;
							MainActivity.changeState(STATE_LOADING);
						}
				}
			//
			break;
		case MESSAGE_PAINT:
			StateMainMenu.DrawBackGroundMenu();
			//
			for (int i = 0; i < menuLevel.length; i++)
				for (int j = 0; j < menuLevel[0].length; j++) {
					if (!StateConfirm.isConfirm && isTouchDrapInRect(menuSelectLevelTopX+ i * MENU_COL_SPACE + menuTouchOffsetX, menuSelectLevelTopY + menuTouchOffsetY + j
							* (menuElementHeight + menuElementSpace),
							menuElementWidth, menuElementHeight)) {
						spriteMenu.drawAFrame(mainCanvas, 0, menuSelectLevelTopX + i * MENU_COL_SPACE, menuSelectLevelTopY + j * (menuElementHeight + menuElementSpace));
					} else if (spriteMenuButton != null && mainCanvas != null) {
						if (i * menuLevel[0].length + j < menuLevelUnLock)
							spriteMenu.drawAFrame(mainCanvas, 1, menuSelectLevelTopX + i * MENU_COL_SPACE, menuSelectLevelTopY + j * (menuElementHeight + menuElementSpace));

						else
							spriteMenu.drawAFrame(mainCanvas, 0, menuSelectLevelTopX + i * MENU_COL_SPACE, menuSelectLevelTopY + j * (menuElementHeight + menuElementSpace));

					}
					fontsmall.drawString(mainCanvas, mainGameLib.getResources()
							.getString(R.string.STRING_LEVEL) + " : " + menuLevel[i][j], menuSelectLevelTopX + i * MENU_COL_SPACE, menuSelectLevelTopY + j
							* (menuElementHeight + menuElementSpace), BitmapFont.ALIGN_CENTER);
					if (i * menuLevel[0].length + j >= menuLevelUnLock) {
						spriteMenu.drawAFrame(mainCanvas, 3, menuSelectLevelTopX + i * MENU_COL_SPACE,
								menuSelectLevelTopY + j * (menuElementHeight + menuElementSpace));
					}
				}

			if (StateConfirm.isConfirm)
				StateConfirm.SendMessageStateConfirm(MESSAGE_PAINT);
			break;
		case MESSAGE_DTOR:
			break;
		}
	}
}
